package com.training.bt.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.training.bt.entity.PeerActivity;

@Mapper
public interface PeerActivityMapper extends BaseMapper<PeerActivity> {

    // 根据用户和Torrent哈希查询活跃做种记录
    @Select("SELECT * FROM peer_activity WHERE user_id = #{userId} AND torrent_hash = #{torrentHash} AND is_seeding = true")
    PeerActivity findActiveSeeding(@Param("userId") Long userId, @Param("torrentHash") String torrentHash);

    // 更新做种状态为停止
    @Update("UPDATE peer_activity SET is_seeding = false, last_announce_time = NOW() WHERE id = #{id}")
    void stopSeeding(@Param("id") Long activityId);
}
